<?php
    include_once("Configs/database.php");
    class NguoiDung extends database{
        private $maso;
        private $matkhau;
        private $maquyen;
        /*public function __construct($maSo, $matKhau){
            $this->maSo = $maSo;
            $this->matKhau = $matKhau;
        } */
        public function setMaSo($maso){
            $this->maso = $maso;
        }
        public function getMaSo(){
            return $this->maso;
        }
        public function setMatKhau($matkhau){
            $this->matkhau = $matkhau;
        }
        public function getMatKhau(){
            return $this->matkhau;
        }
        public function setMaQuyen($maquyen){
            $this->maquyen = $maquyen;
        }
         public function getMaQuyen(){
            return $this->maquyen;
        }
        public function themNguoiDung(){
            $this->setQuery("insert into NguoiDung(maso,matkhau,maquyen) values ('".$this->getMaSo()."','".$this->getMatKhau()."','".$this->getMaQuyen()."')");
            return $this->executeQuery();
        }
        public function suaNguoiDung(){
            $this->setQuery("update NguoiDung set matkhau='".$this->getMatKhau()."',maquyen='".$this->getMaQuyen()."' where maso='".$this->getMaSo()."'");
			// echo $this->getQuery();
            return $this->executeQuery();
        }
         public function xoaNguoiDung(){
            $this->setQuery("delete NguoiDung where maso='".$this->getMaSo()."'");
            return $this->executeQuery();
        }
        public function kiemTra(){
            return $this->isExits("NguoiDung","maso='". $this->maso."' and matkhau = '".$this->matkhau."'");
            //$this->getQuery();
        }
        public function ganQuyen(){
            if ($this->kiemTra()!=0){
                while ($rows = mysql_fetch_array($this->getResult())){
                    $this->setMaQuyen($rows['maquyen']);
               
               } 
            }
            //return $this->getMaQuyen();
        }
        public function dsChucNang(){
            $query = "select b.maso, b.maquyen, e.macn, tencn,link, parent ";
            $query .= "from NguoiDung b, Quyen c, ThucHien d, ChucNang e ";
            $query .= "where b.maso='".$this->getMaSo()."'  and b.maquyen = c.maquyen and c.maquyen=d.maquyen and d.macn=e.macn ";
            return $this->fetchAll();
	
        }
        /*public function hienThiKhoaTheoMaQuyen(){
            $query = "";
            if ($this->getMaQuyen()=='AD'){
                $query = "select * from Khoa";
            }
            if ($this->getMaQuyen()=='DV' || $this->getMaQuyen()=='BM' || $this->getMaQuyen()=='GV'){
                $query = "select a.makhoa, tenkhoa from khoa a, BoMon b, CanBoGiangDay c ";
                $query .= "where c.maso='".$this->getMaSo()."' and a.makhoa = b.makhoa and b.mabm = c.mabm";
            }
            $this->setQuery($query);
            return $this->fetchAll();
        }
        public function hienThiBMTheoKhoaMaQuyen($makhoa){
            if ($this->getMaQuyen()=='AD'){
                $query = "selec * from BoMon where makhoa='".$makhoa."'";
            }
            if ($this->getMaQuyen()=='DV' || $this->getMaQuyen()=='BM' || $this->getMaQuyen()=='GV'){
                $query = "select b.mabm, tenbm from khoa a, BoMon b, CanBoGiangDay c ";
                $query .= "where c.maso='".$this->getMaSo()."' and b.mabm = c.mabm and a.makhoa = b.makhoa and a.makhoa='".$makhoa."'";
            }
            $this->setQuery($query);
            return $this->fetchAll();
        }*/
    }
    //$user = new NguoiDung();
    //$user->setMaSo("1071429");
    //$user->setMatKhau("175187");
    
  
    /*if ($user->kiemTra()!=0){
        echo "Ton tai nguoi dung";
        echo "<br>";
        
        while($rows = mysql_fetch_array($user->getResult())){
            
            $user->setMaQuyen($rows['maQuyen']);
               
        }
        echo $user->getMaQuyen();
    }
    else{
          echo "Khong co nguoi dung nay";  
    }
     echo $user->getQuery(); */
     //$user->ganQuyen();
     //echo $user->getMaQuyen();
?>
